{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Important Note:\n",
    "\n",
    "For your convenience, we have copied the notebook named \"Cats and Dogs Classifier.ipynb\" from Chapter 2 to the GitHub folder for this chapter. Only change in that notebook is that the ImageClassifier class is now defined in its own file named \"image_classifier.py\"; so we have removed that cell and added an import statement instead.\n",
    "\n",
    "Run the \"Cats and Dogs Classifier.ipynb\" notebook in this folder before running this notebook."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "executionInfo": {
     "elapsed": 12318,
     "status": "ok",
     "timestamp": 1630017436556,
     "user": {
      "displayName": "Amit Joglekar",
      "photoUrl": "",
      "userId": "13549820997843161316"
     },
     "user_tz": 300
    },
    "id": "K7FnGDkrmvS7",
    "outputId": "ca201b5f-1b41-4226-d263-0123cf2b7438",
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "!pip install pytorch-lightning --quiet"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "executionInfo": {
     "elapsed": 190,
     "status": "ok",
     "timestamp": 1630019789439,
     "user": {
      "displayName": "Amit Joglekar",
      "photoUrl": "",
      "userId": "13549820997843161316"
     },
     "user_tz": 300
    },
    "id": "bERoMzPAneqn"
   },
   "outputs": [],
   "source": [
    "import torch\n",
    "\n",
    "from image_classifier import CNNImageClassifier"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "executionInfo": {
     "elapsed": 518,
     "status": "ok",
     "timestamp": 1630020834746,
     "user": {
      "displayName": "Amit Joglekar",
      "photoUrl": "",
      "userId": "13549820997843161316"
     },
     "user_tz": 300
    },
    "id": "MkaL4T-jnbYX"
   },
   "outputs": [],
   "source": [
    "model = CNNImageClassifier.load_from_checkpoint(\"./lightning_logs/version_0/checkpoints/epoch=499-step=15499.ckpt\")\n",
    "\n",
    "filepath = \"model.onnx\"\n",
    "input_sample = torch.randn((1, 3, 32, 32))\n",
    "model.to_onnx(filepath, input_sample, export_params=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "colab": {
   "authorship_tag": "ABX9TyNvvNTyZ/VvBwxei2IWq+7L",
   "collapsed_sections": [],
   "name": "cnn-cat-dog-onnx.ipynb",
   "provenance": []
  },
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7-final"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}